<?

class noticeController extends iMVC_Controller{

    public function del(){
    
        $id=$_GET['id']; 
        $notice=new noticeModel();
        $notice->notice_id=$id;
        $notice->del();
        header("location:".$this->getBaseUrl()."admin/notice");
    }   
 
    public function add(){
        $title=$_POST["notice_title"]; 
        $conent=$_POST["content"];
        $time=time();
        echo $title;
        $notice=new noticeModel();
        $notice->notice_title=$title;
        $notice->notice_content=$conent;
        $notice->notice_time=$time;
        $notice->save();
        header("Content-Type:text/html;charset=utf-8");
        echo "<script>alert('添加成功');history.go(-1);</script>";
    
    
    }

    public function noticeList(){
    

        $slider=new sliderModel();
        $sRs=$slider->fetchAll();
        $this->assign("slider",$sRs);

        session_start(); 
        $page=$_GET['page']; 
        $page=empty($page)?1:$page;
        //$size=$_GET['size'];
        //$page=2;
        $size=8;
        $notice=new noticeModel();
        $all=ceil(count($notice->fetchAll())/$size); 
        $rs=$notice->fetchLimit(($page-1)*$size,$size,'notice_time','desc');
        $cRs=$notice->fetchLimit(0,1,'notice_time','desc');
        $this->assign("rs",$rs);
        $this->assign("title",$cRs[0]["notice_title"]);    
        $this->assign("content",$cRs[0]["notice_content"]);    
        $this->assign("time",$cRs[0]["notice_time"]);    
        
        $this->assign("all",$all);
        $this->assign("page",$page);
        if($page>0){
            $this->assign("pre",$page-1);
        }
        if($page<$all){
        
            $this->assign("last",$page+1);
        
        }
        $this->display("notice-list.tpl");    

    
    }

    public function single(){
    
    
        $slider=new sliderModel();
        $sRs=$slider->fetchAll();
        $this->assign("slider",$sRs);
    
        $id=$_REQUEST["id"];

        $notice=new noticeModel();
        $notice->findByPk($id);

        $this->assign("title",$notice->notice_title);    
        $this->assign("content",$notice->notice_content);    
        $this->assign("time",$notice->notice_time);    
        
        $this->display("notice-single.tpl");    
    
    }

}
// vim600:ts=4 st=4 foldmethod=marker foldmarker=<<<,>>>
// vim600:syn=php commentstring=//%s
